package cn.stylefeng.guns.modular.pandian.service.impl;

import cn.stylefeng.guns.base.pojo.page.LayuiPageFactory;
import cn.stylefeng.guns.base.pojo.page.LayuiPageInfo;
import cn.stylefeng.guns.modular.pandian.entity.PandianJihuaDetailed;
import cn.stylefeng.guns.modular.pandian.mapper.PandianJihuaDetailedMapper;
import cn.stylefeng.guns.modular.pandian.model.params.PandianJihuaDetailedParam;
import cn.stylefeng.guns.modular.pandian.model.result.PandianJihuaDetailedResult;
import  cn.stylefeng.guns.modular.pandian.service.PandianJihuaDetailedService;
import cn.stylefeng.roses.core.util.ToolUtil;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.springframework.stereotype.Service;

import java.io.Serializable;
import java.util.List;

/**
 * 盘点明细表 服务实现类
 */
@Service
public class PandianJihuaDetailedServiceImpl extends ServiceImpl<PandianJihuaDetailedMapper, PandianJihuaDetailed> implements PandianJihuaDetailedService {

    @Override
    public void add(PandianJihuaDetailedParam param){
        PandianJihuaDetailed entity = getEntity(param);
        this.save(entity);
    }

    @Override
    public void delete(PandianJihuaDetailedParam param){
        this.removeById(getKey(param));
    }

    @Override
    public void update(PandianJihuaDetailedParam param){
        PandianJihuaDetailed oldEntity = getOldEntity(param);
        PandianJihuaDetailed newEntity = getEntity(param);
        ToolUtil.copyProperties(newEntity, oldEntity);
        this.updateById(newEntity);
    }

    @Override
    public PandianJihuaDetailedResult findBySpec(PandianJihuaDetailedParam param){
        return this.baseMapper.findBySpec(param);
    }

    @Override
    public List<PandianJihuaDetailedResult> findListBySpec(PandianJihuaDetailedParam param){
        return null;
    }

    @Override
    public LayuiPageInfo findPageBySpec(PandianJihuaDetailedParam param,String condition){
        Page pageContext = getPageContext();
        IPage page = this.baseMapper.customPageList(pageContext, param,condition);
        return LayuiPageFactory.createPageInfo(page);
    }

    private Serializable getKey(PandianJihuaDetailedParam param){
        return param.getId();
    }

    private Page getPageContext() {
        return LayuiPageFactory.defaultPage();
    }

    private PandianJihuaDetailed getOldEntity(PandianJihuaDetailedParam param) {
        return this.getById(getKey(param));
    }

    private PandianJihuaDetailed getEntity(PandianJihuaDetailedParam param) {
        PandianJihuaDetailed entity = new PandianJihuaDetailed();
        ToolUtil.copyProperties(param, entity);
        return entity;
    }

	@Override
	public PandianJihuaDetailedResult sumByspec(PandianJihuaDetailedParam param) {
		return this.baseMapper.sumByspec(param);
	}

	@Override
	public PandianJihuaDetailedResult findPanDianPositionBySpec(PandianJihuaDetailedParam pandianJihuaDetailedParam,
			Long userId, Long diskId) {
		return this.baseMapper.findPanDianPositionBySpec(pandianJihuaDetailedParam,userId,diskId);
	}

	@Override
	public List<PandianJihuaDetailedResult> findPanDianGoodsListBySpec(
			PandianJihuaDetailedParam pandianJihuaDetailedParam, Long userId, Long diskId) {
		return this.baseMapper.findPanDianGoodsListBySpec(pandianJihuaDetailedParam,userId,diskId);
	}

	@Override
	public List<PandianJihuaDetailedResult> findPanDianTrayListBySpec(
			PandianJihuaDetailedParam pandianJihuaDetailedParam, Long userId, Long diskId) {
		return this.baseMapper.findPanDianTrayListBySpec(pandianJihuaDetailedParam,userId,diskId);
	}

	@Override
	public List<PandianJihuaDetailedResult> findPanDianPositionListBySpec(
			PandianJihuaDetailedParam pandianJihuaDetailedParam, Long userId, Long diskId) {
		return this.baseMapper.findPanDianPositionListBySpec(pandianJihuaDetailedParam,userId,diskId);
	}

}
